package com.hc.util;

import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;





public class SystemConfigUtil {


	
	public static final String FILEPATH="systemFile/systemConfig.properties";
	
	public static void readConfig(){
		
		
	File file = new File(FILEPATH);
		
		FileReader fileReader = null;

			try {
				fileReader = new  FileReader(file);
			} catch (FileNotFoundException e1) {
					e1.printStackTrace();
			}
			BufferedReader reader = new BufferedReader(fileReader);
			String linStr = "";
			

			
			try {
				while((linStr=reader.readLine())!=null){
					
				String[] results= 	linStr.split("=");
					
					if(results[0].equals("window_hight")){
						CommonData.window_hight = Integer.parseInt(results[1]);
					}else if(results[0].equals("window_width")){
						CommonData.window_width = Integer.parseInt(results[1]);
					}else if(results[0].equals("number")){
						CommonData.number = results[1];
					}else if(results[0].equals("pwd")){
						CommonData.pwd = results[1];
					}else if(results[0].equals("useLogin")){
						CommonData.useLogin = Boolean.parseBoolean(results[1]);
					}else if(results[0].equals("welcomSleepTime")){
						CommonData.welcomSleepTime = Long.parseLong(results[1]);
					}
				}
				
				reader.close();
				fileReader.close();
			} catch (IOException e) {
					e.printStackTrace();
			}


	}
	
	public static void writeConfig(){
		StringBuilder sb = new StringBuilder();

			sb.append("window_hight=").append(CommonData.window_hight).append("\n");
			sb.append("window_width=").append(CommonData.window_width).append("\n");
			sb.append("number=").append(CommonData.number).append("\n");
			sb.append("pwd=").append(CommonData.pwd).append("\n");
			sb.append("useLogin=").append(CommonData.useLogin).append("\n");
			sb.append("welcomSleepTime=").append(CommonData.welcomSleepTime).append("\n");
		File file = new File(FILEPATH);
		FileWriter w;
		try {
			w = new FileWriter(file);
			w.write(sb.toString());
			w.flush();
			w.close();
		} catch (IOException e) {
			e.printStackTrace();
			
		}
	
	

	}
	public static void main(String[] args) {
	
		SystemConfigUtil.readConfig();
		SystemConfigUtil.writeConfig();
	
	}

}
